/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            productCategoryManageInfo: {
                cateTypeName: ["", "常规商品", "非常规商品", "积分商品"],
                productCategorys: [],
                total: 0,
                records: 1,
                moreCondition: false,
                categoryId: '',
                isShows: [],
                cateTypes: [],
                conditions: {
                    categoryName: '',
                    categoryLevel: '',
                    cateType: '',
                    isShow: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {

            $that._listProductCategorys(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('product_category', "is_show", function (_data) {
                $that.productCategoryManageInfo.isShows = _data;
            });
            vc.getDict('product_category', "cate_type", function (_data) {
                $that.productCategoryManageInfo.cateTypes = _data;
            });
        },
        _initEvent: function () {
            vc.on('productCategoryManage', 'listProductCategory', function (_param) {
                $that._listProductCategorys(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listProductCategorys(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listProductCategorys: function (_page, _rows) {
                $that.productCategoryManageInfo.conditions.page = _page;
                $that.productCategoryManageInfo.conditions.row = _rows;
                $that.productCategoryManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                
                let param = {
                    params: $that.productCategoryManageInfo.conditions
                };
                param.params.categoryName = param.params.categoryName.trim();
                //发送get请求
                vc.http.apiGet('/productCategory.queryProductCategory',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.productCategoryManageInfo.total = _json.total;
                        $that.productCategoryManageInfo.records = _json.records;
                        $that.productCategoryManageInfo.productCategorys = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.productCategoryManageInfo.records,
                            dataCount: $that.productCategoryManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddProductCategoryModal: function () {
                vc.emit('addProductCategory', 'openAddProductCategoryModal', {});
            },
            _openEditProductCategoryModel: function (_productCategory) {
                vc.emit('editProductCategory', 'openEditProductCategoryModal', _productCategory);
            },
            _openDeleteProductCategoryModel: function (_productCategory) {
                vc.emit('deleteProductCategory', 'openDeleteProductCategoryModal', _productCategory);
            },
            _queryProductCategoryMethod: function () {
                $that._listProductCategorys(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _resetProductCategoryMethod: function () {
                $that.productCategoryManageInfo.conditions.categoryName = "";
                $that.productCategoryManageInfo.conditions.cateType = "";
                $that.productCategoryManageInfo.conditions.isShow = "";
                $that._listProductCategorys(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.productCategoryManageInfo.moreCondition) {
                    $that.productCategoryManageInfo.moreCondition = false;
                } else {
                    $that.productCategoryManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
